
'use strict';

/**
	Part of Zombie Navigator
	Copyright © 2015  Zombie Navigator Developers
	
	@file
	@license AGPL-3.0+
*/


/*
	Zombie script example (= unprivileged)
	Do NOT require () this script from the addon code.
	
	demo_ID: 'promise'
	A basic example of a Zombie script
*/


const {zombie, console} = require('zombie/zombie');
const {openWindow, closeAll} = require('zombie/webbrowser');
const {run} = require('zombie/async');


try {
	run(function* () {
		try {
			yield new Promise(function (resolve, reject) {
				reject(new Error('Error!'));
			});
		} catch (e) {
			console.log('Error inside coroutine:', e);
			closeAll();
			let result = yield new Promise(function (resolve, reject) {
				resolve(42);
			});
			console.log('result:', result);
			
			throw e;
		}
	})
	.catch(function (e) {
		console.log('Error via promise:', e + '');
		closeAll();
	});
} catch (e) {
	console.log('Error:', e + '');
	closeAll();
}


// vim: ts=4 noet ai

